//
//  ViewController.m
//  练习2
//
//  Created by qianfeng0 on 16/4/15.
//  Copyright © 2016年 heziheng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property UIScrollView *scrollView;
@property NSMutableArray *images;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"相册";
    self.images=[[NSMutableArray alloc]initWithArray:[NSBundle pathsForResourcesOfType:@"png" inDirectory:[NSBundle mainBundle].resourcePath]];
    [self createScrollView];
//    [self createViewController];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//-(void)createViewController{
//    Class cla=NSClassFromString(@"ViewController1");
//    UIViewController *vc=[[cla alloc]init];
//    
//}
-(void)createScrollView{
    CGSize size=self.view.bounds.size;
    self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height-64)];
    for (NSInteger i=0; i<self.images.count; i++) {
        UIImage *image=[UIImage imageWithContentsOfFile:self.images[i]];
        UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(i%3*(size.width/3), (i/3)*(size.width/3), size.width/3, size.width/3)];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.image=image;
        [self.scrollView addSubview:imageView];
    }
//    self.scrollView.backgroundColor=[UIColor redColor];
    self.scrollView.contentSize=CGSizeMake(size.width, ((self.images.count-1)/3+1)*size.width/3);
    [self.view addSubview:self.scrollView];
}

@end
